//小说推荐
import 'package:get/get.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:xvideos/hj_model/cartoon_media_info.dart';
import 'package:xvideos/hj_utils/api_service/acg_service.dart';

class CartoonRecommendLogic extends GetxController {
  String? mediaId;
  RefreshController refreshCtr = RefreshController();
  int currentPage = 1;
  List<CartoonMediaInfo>? dataList;

  CartoonRecommendLogic({this.mediaId});

  @override
  onReady() {
    super.onReady();
    loadData();
  }

  loadData({int pageNum = 1, bool showLoading = false}) async {
    dataList ??= [];

    final model = await ACGService.comicsRecommendList(pageNum, 12, mediaId: mediaId);

    if (model != null) {
      currentPage = pageNum;
      if (pageNum == 1) dataList?.clear();
      dataList?.addAll(model.list ?? []);
      update();
      model.hasNext == true ? refreshCtr.loadComplete() : refreshCtr.loadNoData();
      refreshCtr.refreshCompleted();
    }
  }

  loadMoreData() async => loadData(pageNum: currentPage + 1);
}
